//
//  OMGGroupSecViewController.m
//  A_project2.0
//
//  Created by dllo on 16/3/15.
//  Copyright © 2016年 七平. All rights reserved.
//

#import "OMGGroupSecViewController.h"

#import "OMGGongLueCollectionViewCell.h"
#import "OMGNewCollectionViewCell.h"
#import "OMGWenDaCollectionViewCell.h"

#import "OMGWebViewViewController.h"
#import "ColorClass.h"

#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@interface OMGGroupSecViewController ()<UIScrollViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, secWebPushDelegate, gongLueWebPushDelegate, wenDaPushDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UIButton *zuixinButton;
@property (nonatomic, strong) UIButton *gonglueButton;
@property (nonatomic, strong) UIButton *wendaButton;
@property (nonatomic, strong) UIView *line;
@end

@implementation OMGGroupSecViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createCollectionView];
    
  
    // 最新buttton
    self.zuixinButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _zuixinButton.frame = CGRectMake(0, 64, WIDTH / 3 , HEIGHT / 16);
    _zuixinButton.backgroundColor = [UIColor whiteColor];
    [_zuixinButton setTitle:@"最新" forState:UIControlStateNormal];
    [_zuixinButton addTarget:self action:@selector(zuixinAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view  addSubview:_zuixinButton];
    // 攻略button
    self.gonglueButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _gonglueButton.frame = CGRectMake(WIDTH / 3, 64, WIDTH / 3 , HEIGHT / 16);
    _gonglueButton.backgroundColor = [UIColor whiteColor];
    [_gonglueButton setTitle:@"攻略" forState:UIControlStateNormal];
    [_gonglueButton addTarget:self action:@selector(gonglueAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_gonglueButton];
    // 问题button
    self.wendaButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _wendaButton.frame = CGRectMake(WIDTH - WIDTH / 3 , 64, WIDTH / 3, HEIGHT / 16);
    _wendaButton.backgroundColor = [UIColor whiteColor];
    [_wendaButton setTitle:@"问答" forState:UIControlStateNormal];
    [_wendaButton addTarget:self action:@selector(wendaAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_wendaButton];
    
    
    // 跟随线
    self.line = [[UIView alloc] initWithFrame:CGRectMake(0, 104, WIDTH / 3, 3)];
    _line.backgroundColor = [ColorClass stringToColor:@"#DCDCDC"];
    [self.view addSubview:_line];
}

- (void)createCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    // cell大小
    layout.itemSize = CGSizeMake(self.view.frame.size.width, 677);
    // 行列间距
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    // 边界
    layout.sectionInset = UIEdgeInsetsMake(98, 0, 49, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    // 边距
    _collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 10);
    self.automaticallyAdjustsScrollViewInsets = YES;
    // 整页滑动
    _collectionView.pagingEnabled = YES;
    // 弹动效果
    _collectionView.bounces = NO;
    [self.view addSubview:_collectionView];
    
    // 重用池
    [_collectionView registerClass:[OMGNewCollectionViewCell class] forCellWithReuseIdentifier:@"newcell"];
    
    [_collectionView registerClass:[OMGGongLueCollectionViewCell class] forCellWithReuseIdentifier:@"gongluecell"];
    
    [_collectionView registerClass:[OMGWenDaCollectionViewCell class] forCellWithReuseIdentifier:@"wendacell"];
    
    ;

}

#pragma mark - 线条跟随collectioncell动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (_collectionView.contentOffset.x == WIDTH) {
        _line.center = CGPointMake(WIDTH / 2, 104);
    } else if (_collectionView.contentOffset.x == WIDTH * 2) {
        _line.center = CGPointMake(WIDTH * 5 / 6, 104);
        
    } else if (_collectionView.contentOffset.x == 0){
        _line.center = CGPointMake(WIDTH / 6, 104);
    }
}

#pragma mark - cell设置
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"~~~~~~~~~~~~%ld", indexPath.item);
    if (indexPath.item == 0) {
        
        OMGNewCollectionViewCell *cellNew = [collectionView dequeueReusableCellWithReuseIdentifier:@"newcell" forIndexPath:indexPath];
        cellNew.str = self.str;
        cellNew.delegate = self;
        
        return cellNew;
        
    }else if(indexPath.item == 1){
        
        OMGGongLueCollectionViewCell *cellGonglue = [collectionView dequeueReusableCellWithReuseIdentifier:@"gongluecell" forIndexPath:indexPath];
        cellGonglue.str = self.str;
        cellGonglue.delegate = self;
        return cellGonglue;
        
    } else {
        
        OMGWenDaCollectionViewCell *cellWenda = [collectionView dequeueReusableCellWithReuseIdentifier:@"wendacell" forIndexPath:indexPath];
        cellWenda.str = self.str;
        cellWenda.delegate = self;
        return cellWenda ;
        
    }
}


#pragma mark - item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 3;
    
}

#pragma mark - button方法
- (void)zuixinAction
{
    
    [_collectionView setContentOffset:CGPointMake(0, -HEIGHT / 10) animated:YES];
}
- (void)gonglueAction
{
    
    [_collectionView setContentOffset:CGPointMake(WIDTH ,-HEIGHT / 10) animated:YES];
}
- (void)wendaAction
{
    [_collectionView setContentOffset:CGPointMake(WIDTH * 2, -HEIGHT / 10) animated:YES];
    
}


#pragma mark - 最新collectioncell点击跳转webview
- (void)secWebPush:(NSString *)str
{
    OMGWebViewViewController *cellVC = [[OMGWebViewViewController alloc] init];
    cellVC.urlStr = str;
    
    [self.navigationController pushViewController:cellVC animated:YES];

}
#pragma mark - 攻略collectioncell点击跳转webview
- (void)gongLueWebPush:(NSString *)str
{
    OMGWebViewViewController *cellVC = [[OMGWebViewViewController alloc] init];
    cellVC.urlStr = str;
    [self.navigationController pushViewController:cellVC animated:YES];

    
}
#pragma mark -  问答collectioncell点击跳转webview
- (void)wenDaPush:(NSString *)str
{
    OMGWebViewViewController *cellVC = [[OMGWebViewViewController alloc] init];
    cellVC.urlStr = str;
    [self.navigationController pushViewController:cellVC animated:YES];
    
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
